﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows;
using System.Windows.Input;

namespace Shrestha.Trigraph
{
    class TriClusterMarker: Shape
    {
        private double x1;
        private double x2;
        private double x3;
        private double x4;
        private double y1;
        private double y2;
        private double y3;
        private double y4;
        private TriClusterEvent triClusterEvent;
        private MainWindow mainWindow;

        public TriClusterMarker(double x1, double x2, double x3, double x4, double y1, double y2, double y3, double y4, TriClusterEvent e, MainWindow mainWindow)
        {
            this.x1 = x1;
            this.x2 = x2;
            this.x3 = x3;
            this.x4 = x4;
            this.y1 = y1;
            this.y2 = y2;
            this.y3 = y3;
            this.y4 = y4;
            this.triClusterEvent = e;
            this.mainWindow = mainWindow;
            this.Stroke = Brushes.Blue;
            this.Fill = Brushes.LightSkyBlue;
            this.Opacity = 0.5;
        }

        public TriClusterMarker() { }

        protected override Geometry DefiningGeometry
        {
            get
            {
                StreamGeometry geometry = new StreamGeometry();
                geometry.FillRule = FillRule.EvenOdd;

                using (StreamGeometryContext context = geometry.Open())
                {
                    InternalTriMarkerGeometry(context);
                }
                geometry.Freeze();

                return geometry;
            }
        }

        private void InternalTriMarkerGeometry(StreamGeometryContext context)
        {
            Point p1 = new Point(x1, y1);
            Point p2 = new Point(x2, y2);
            Point p3 = new Point(x4,y4);
            Point p4 = new Point(x3, y3);

            context.BeginFigure(p1, true, true);
            context.LineTo(p2, true, true);
            context.LineTo(p3, true, true);
            context.LineTo(p4, true, true);
        }

        //protected override void OnMouseDown(MouseButtonEventArgs e)
        //{
        //    string descriptionText = "Latitude: " + te.Latitude + ", Longitude: " + te.Longitude + "\nDate of Event: " + te.EventDate;
        //    baseWindow.descriptionBlock.Text = descriptionText;

        //    this.Stroke = Brushes.Red;
        //    this.Fill = Brushes.PeachPuff;

        //    base.OnMouseDown(e);
        //}

        protected override void OnMouseEnter(MouseEventArgs e)
        {
            this.Stroke = Brushes.Red;
            this.Fill = Brushes.PeachPuff;
            this.StrokeThickness = 3;
            base.OnMouseEnter(e);
        }

        protected override void OnMouseLeave(MouseEventArgs e)
        {
            this.Stroke = Brushes.Blue;
            this.Fill = Brushes.LightSkyBlue;
            this.StrokeThickness = 1.0;
            base.OnMouseLeave(e);
        }

        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            mainWindow.ZoomOn(triClusterEvent);
            base.OnMouseDown(e);
        }


    }
}
